//
//  DiagnosisAutoViewController.m
//  MobileChecker
//
//  Created by Lymons on 15-1-5.
//  Copyright (c) 2015年 Lymons. All rights reserved.
//

#import "DiagnosisAutoViewController.h"
#import "CheckAutoItemViewModel.h"
#import "SystemUtils.h"
#import "LayoutUtils.h"
#import "AppDelegate.h"

@interface DiagnosisAutoViewController ()

@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UILabel *headerString;
@property (strong, nonatomic) IBOutlet UILabel *gpsLabel;
@property (strong, nonatomic) IBOutlet UILabel *magneticLabel;
@property (strong, nonatomic) IBOutlet UILabel *gyroLabel;
@property (strong, nonatomic) IBOutlet UIView *monitorView;
@property (strong, nonatomic) IBOutlet UILabel *luminaLabel;
@property (strong, nonatomic) IBOutlet UIButton *nextButton;
@property (strong, nonatomic) IBOutlet UIButton *recheckButton;

@property (nonatomic) CheckAutoItemViewModel *viewModel;

@end

@implementation DiagnosisAutoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.monitorView.hidden = YES;
    
    self.viewModel = [[CheckAutoItemViewModel alloc] init];
    self.viewModel.tableViewCellIdentifier = @"CheckItemTableViewCell";
    self.tableView.dataSource = self.viewModel;
    
    self.recheckButton.rac_command = self.viewModel.recheckCommand;
    
    @weakify(self);
    [RACObserve(self.viewModel, headerString) subscribeNext:^(NSString* str) {
        @strongify(self);
        self.headerString.text = str;
        [self.tableView reloadData];
    }];
    RAC(self, gpsLabel.text) = RACObserve(self.viewModel, gpsString);
    RAC(self, gyroLabel.text) = RACObserve(self.viewModel, gyroString);
    RAC(self, magneticLabel.text) = RACObserve(self.viewModel, magneticString);
    RAC(self, luminaLabel.text) = RACObserve(self.viewModel, luminaString);
    RAC(self, monitorView.hidden) = RACObserve(self.viewModel, hideMonitor);
    RAC(self, nextButton.enabled) = RACObserve(self.viewModel, checkCompleted);
    [[self rac_signalForSelector:@selector(viewDidDisappear:)] subscribeNext:^(id x) {
        @strongify(self);
        self.viewModel.checkCompleted = YES;
    }];
    
    [self.viewModel startCheck];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
